//
//  CreateVolumeDelegate.m
//  cTypica
//
//  Created by David Kavanagh on 2/16/09.
//  Copyright 2009 directThought. All rights reserved.
//

#import "CreateVolumeDelegate.h"

@implementation CreateVolumeDelegate
@synthesize volumeInfo, formatter;

+ (id)delegate {
	CreateVolumeDelegate *ret = [self alloc];
	ret.formatter = [[NSDateFormatter alloc] init];
	[ret.formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
	return ret;
}

- (void) dealloc {
	[formatter release];
	[super dealloc];
}

// XML parser delegate methods
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"CreateVolumeResponse"]) {
		self.volumeInfo = [VolumeInfo alloc];
	}
}

- (void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	NSString *cleanString = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	[currentStringValue setString:@""];
	if ([elementName isEqualToString:@"volumeId"]) {
		volumeInfo.volumeId = cleanString;
	}
	else if ([elementName isEqualToString:@"size"]) {
		volumeInfo.volSize = cleanString;
	}
	else if ([elementName isEqualToString:@"snapshotId"]) {
		volumeInfo.snapshotId = cleanString;
	}
	else if ([elementName isEqualToString:@"zone"]) {
		volumeInfo.zone = cleanString;
	}
	else if ([elementName isEqualToString:@"status"]) {
		volumeInfo.status = cleanString;
	}
	else if ([elementName isEqualToString:@"createTime"]) {
		volumeInfo.createTime = [formatter dateFromString:cleanString];
		//[cleanString release];
	}
}
@end
